import java.util.Arrays;
import java.util.ArrayList;

public class MiningNobel {

	public static int threeSum(int[] a)
	{ 
		// Count triples that sum to 0.
		Arrays.sort(a);
		int N = a.length;
		int cnt = 0;
		for (int i = 0; i < N; i++)
			for (int j = 0; j < N; j++)
				if (BinarySearch.rank(-a[i]-a[j], a) > j){
					cnt++;
					System.out.println("Combination: " + a[i] + " " + a[j]);
				}
		return cnt;
	}

	public static int fourSum(double[] a)
	{
		int N = a.length;
		int count = 0;
		for (int i = 0; i < N; i++)
			for (int j = 0; j < N; j++)
				for (int k = 0; k < N; k++)
					for (int l = 0; l < N; l++)
						if (a[i] + a[j] + a[k] + a[l] == 0)
							count++;
		return count;
	}

	public static void main(String[] args)
	{
		String[] tmp;
		ArrayList<Double> numbers = new ArrayList<Double>();
		double[] a;
		Stopwatch stopwatch = new Stopwatch();
		try {
			tmp = In.readStrings(args[0]);
			for(int i = 0; i < tmp.length ; i++) {
				if(tmp[i].contains(",")) {
					numbers.add(Double.parseDouble(tmp[i+1]));
					}
				}
			tmp = null;
			a = new double[numbers.size()];
			int count = 0;
			for(Double d : numbers) {
				a[count++] = d;
				}
			numbers = null;
			StdOut.println("FourSum - Count: " + fourSum(a));
			double time = stopwatch.elapsedTime();
			StdOut.println("Elapsed time: " + time + " seconds \n");
			StdOut.println("FastFourSum - Count: " + fastFourSum(a));
			double time2 = stopwatch.elapsedTime();
			StdOut.println("Elapsed time: " + (time2-time) + " seconds \n");
			}

		catch (Exception exn) {
			System.out.println(exn);
		}
		

		
	}

	public static int fastFourSum(double[] a)
	{ 
		// Count quadruples that sum to 0.
		Arrays.sort(a);
		int N = a.length;
		int cnt = 0;
		for (int i = 0; i < N; i++)
			for (int j = 0; j < N; j++)
				for (int k = 0; k < N; k++)
					if (BinarySearchDb.rank(-a[i]-a[j]-a[k], a) >= 0){
						cnt++;
					}
		return cnt;
	}

	public static class BinarySearchDb {
		// precondition: array a[] is sorted
		public static int rank(double key, double[] a) {
			int lo = 0;
			int hi = a.length - 1;
			while (lo <= hi) {
				// Key is in a[lo..hi] or not present.
				int mid = lo + (hi - lo) / 2;
				if      (key < a[mid]) hi = mid - 1;
				else if (key > a[mid]) lo = mid + 1;
				else return mid;
			}
			return -1;
		}
	}	
}